<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>to_do_list</title>
    <script src="vue2/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="inputValue.message" />
        <button @click="handleBtn">提交</button>
        <ul>
            <todo-item :content="item" :index="index" v-for="(item,index) in list" @delete="handleItemDelete">
            </todo-item>
        </ul>
    </div>
    <script>
        var TodoItem = {
            props: ["content", "index"],
            template: '<li @click="handleItem">{{ content.message }}</li>',
            methods: {
                handleItem: function () {
                    this.$emit("delete", this.index);
                }
            }
        };
        var app = new Vue({
            el: "#app",
            components: {
                TodoItem: TodoItem
            },
            data: {
                list: [{
                        message: "Foo"
                    },
                    {
                        message: "Bar"
                    }
                ],
                inputValue: {
                    message: "aaa"
                }
            },
            methods: {
                handleBtn: function () {
                    let aa = {
                        message: this.inputValue.message
                    };
                    this.list.push(aa);
                },
                handleItemDelete: function (index) {
                    this.list.splice(index, 1);
                }
            }
        });
    </script>
</body>

</html>